﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PeekWebApp.Management.AjaxHandler
{
    /// <summary>
    /// ContentInterestEditHandler 的摘要说明
    /// </summary>
    public class ContentInterestEditHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            string action = context.Request["action"];
            if (action.Equals("Edit"))//编辑
            {
                string title = context.Request["title"].Trim();
                string remark = context.Request["remark"].Trim();
                string content = context.Request["content"];
                string code = context.Request["hidCode"];
                PeekService.ContentInterest model = new PeekService.ContentInterestService().GetModel(code);
                if (model == null)
                {
                    model = new PeekService.ContentInterest();
                    model.Code = Guid.NewGuid().ToString();
                    model.CreateID = "";
                    model.CreateTime = DateTime.Now;
                    model.State = 0;
                    model.Sort = new PeekService.ExtendService().GetSort("ContentInterest");
                    model.Content = context.Server.HtmlDecode(content);
                    model.Title = title;
                    model.Remark = remark;
                    new PeekService.ContentInterestService().Add(model);
                }
                else
                {
                    model.Content = context.Server.HtmlDecode(content);
                    model.Title = title;
                    model.Remark = remark;
                    new PeekService.ContentInterestService().Update(model);
                }
                context.Response.Redirect("../ContentInterest/List.aspx");
            }
            else //绑定
            {
                string code = context.Request["hidCode"];
                PeekService.ContentInterest type = new PeekService.ContentInterestService().GetModel(code);
                context.Response.Write(PeekService.CommonService.ConvertToJSON(type));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}